﻿<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web.Routing" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        RouteTable.Routes.MapConnection<LogUsers>("echo", "/echo/{*operation}");
        RouteTable.Routes.MapHubs();
        
        RegisterAllRoutes(System.Web.Routing.RouteTable.Routes);
        //System.Web.Routing.RouteTable.Routes.MapConnection<LogUsers>("echo", "/echo/{*operation}");

    }

    private void RegisterAllRoutes(System.Web.Routing.RouteCollection routes)
    {
        routes.RouteExistingFiles = true;
        IngoreRoutes(routes);
        RegisterFrontendRoutes(routes);
    }

    private void IngoreRoutes(System.Web.Routing.RouteCollection routes)
    {
        routes.Ignore("{resource}.axd/{*pathInfo}");
        routes.Ignore("{file}.txt");
        routes.Add(new System.Web.Routing.Route("{resource}.axd/{*pathInfo}", new System.Web.Routing.StopRoutingHandler()));
        
    }

    private void RegisterFrontendRoutes(System.Web.Routing.RouteCollection routes)
    {
        routes.MapPageRoute("HomePage", "{home}", "~/default.aspx", true,
                new System.Web.Routing.RouteValueDictionary { { "home", "home" } },
                new System.Web.Routing.RouteValueDictionary { { "home", "home|default.aspx|" } });
        routes.MapPageRoute("ForgotPassword", "forgot-password", "~/forgotPassword.aspx");

        routes.MapPageRoute("MembersInformation", "members-information", "~/MemebersInfo.aspx");
        routes.MapPageRoute("Logout", "logout", "~/Logout.aspx");
        //routes.MapPageRoute("Favorites", "favorites", "~/Favorites_App.aspx");
        routes.MapPageRoute("Forum", "forum", "~/Forum.aspx");
        routes.MapPageRoute("Advertising", "advertising", "~/Advertising.aspx");
        routes.MapPageRoute("ContactAdmin", "contact-administrator", "~/ContactAdmin.aspx");
        routes.MapPageRoute("CustomerService", "customer-service", "~/CustomerService.aspx");
        routes.MapPageRoute("Sitemap", "sitemap", "~/Sitemap.aspx");
        routes.MapPageRoute("Terms", "terms", "~/Terms.aspx");
        routes.MapPageRoute("Copyrights", "copyrights", "~/CopyRight.aspx");
        routes.MapPageRoute("PrivacyPolicy", "privacy-policy", "~/PrivacyPolicy.aspx");
    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs
        //HttpContext ctx = HttpContext.Current;

        //Exception exception = ctx.Server.GetLastError();

        //string errorInfo =
        //   "<br>Offending URL: " + ctx.Request.Url.ToString() +
        //   "<br>Source: " + exception.Source +
        //   "<br>Message: " + exception.Message +
        //   "<br>Message: " + exception.InnerException.Message +
        //   "<br>Stack trace: " + exception.StackTrace;

        //string senderMailAdress = ConfigurationManager.AppSettings["senderMailAdress"].ToString();
        //string host = ConfigurationManager.AppSettings["host"].ToString();
        //System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();

        ////create mail message body
        //System.Text.StringBuilder sb = new System.Text.StringBuilder();
        //mail.IsBodyHtml = true;
        //mail.BodyEncoding = System.Text.Encoding.UTF8;

        //mail.Body = errorInfo;
        //mail.To.Add(new System.Net.Mail.MailAddress("ratkop@gmail.com"));
        //mail.Bcc.Add("info@transportexchange.org");
        //mail.From = new System.Net.Mail.MailAddress(senderMailAdress);
        //mail.Subject = "TransportExchange.org Error";

        //System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();

        ////set SmtpClient properties
        //smtpClient.Port = 25;
        //smtpClient.Host = "173.192.111.22";

        //string username = ConfigurationManager.AppSettings["username"].ToString();
        //string password = ConfigurationManager.AppSettings["password"].ToString();
        //smtpClient.Credentials = new System.Net.NetworkCredential(username, password);
        //try
        //{
        //    smtpClient.Send(mail);
        //}
        //catch { }
        //ctx.Response.Write(errorInfo);

        //// --------------------------------------------------
        //// To let the page finish running we clear the error
        //// --------------------------------------------------
        //ctx.Server.ClearError();
        ////Response.Redirect("~/teerror.aspx");

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
       
</script>
